﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TodayWhoModel;
namespace TodayWho
{
    public partial class account2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["userId"] == null)
                {
                    Response.Redirect("error.aspx");
                }
                txtEmail.Text = Session["email"].ToString();
                ddListCategory.SelectedValue = Session["categoryId"].ToString();
            }
        }
        protected void btnEmail_onClick(object sender, EventArgs e)
        {
            UserModel userModel = new UserModel();
            userModel.Email = txtEmail.Text.Trim();
            userModel.UserId = Int32.Parse(Session["userId"].ToString());
            if (!userModel.UpdateEmail())
            {
                lblMessage.Text = "Email adresi degistirelemedi. Email adresi zaten kullaniliyor..";
                lblMessage.Visible = true;
            }
            else
            {
                Session["email"] = userModel.Email;
                lblMessage.Text = "Email adresi basariyla degistirilmistir..";
                lblMessage.Visible = true;
            }

        }
        protected void btnCategory_onClick(object sender, EventArgs e)
        {
            UserModel userModel = new UserModel();
            userModel.CategoryId = Int32.Parse(ddListCategory.SelectedValue);
            userModel.UserId = Int32.Parse(Session["userId"].ToString());
            if (!userModel.UpdateCategory())
            {
                lblMessage.Text = "Kategori degistirilemedi..";
                lblMessage.Visible = true;
            }
            else
            {
                Session["categoryId"] = userModel.CategoryId;
                lblMessage.Text = "Kategori basariyla degistirilmistir..";
                lblMessage.Visible = true;
            }
        }
        
    }
}